package com.eagle.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.eagle.common.entity.enums.PageSize;
import com.eagle.common.entity.po.AdminUser;
import com.eagle.common.entity.po.query.AdminUserQuery;
import com.eagle.common.entity.vo.PaginationResult;
import com.eagle.common.entity.vo.SimplePage;
import com.eagle.common.exception.BusinessException;
import com.eagle.common.mapper.AdminUserMapper;
import com.eagle.common.service.AdminUserService;

/**
 * 
 * 后台用户表 业务接口实现
 * 
 */
@Service("adminUserService")
public class AdminUserServiceImpl implements AdminUserService {

private static final Logger logger = LoggerFactory.getLogger(AdminUserServiceImpl.class);	@Resource
	private AdminUserMapper<AdminUser,AdminUserQuery> adminUserMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<AdminUser> findListByParam(AdminUserQuery param) {
		List<AdminUser> list = this.adminUserMapper.selectList(param);
		return list;
	}

	/**
	 * 根据条件查询列表
	 */
	public Integer findCountByParam(AdminUserQuery param) {
		Integer count = this.adminUserMapper.selectCount(param);
		return count;
	}

	/**
	 * 分页查询方法
	 */
	public PaginationResult<AdminUser> findListByPage(AdminUserQuery param) {
		int count = this.adminUserMapper.selectCount(param);
		int pageSize = param.getPageSize()==null?PageSize.SIZE15.getSize():param.getPageSize();
		int pageNo = 0;
		if (null != param.getPageNo()) {
			pageNo=param.getPageNo();
		}
		SimplePage page = new SimplePage(pageNo, count, pageSize);
		param.setSimplePage(page);
		List<AdminUser> list = this.adminUserMapper.selectList(param);
		PaginationResult<AdminUser> result = new PaginationResult<AdminUser>(page, list);
		return result;
	}

	/**
	 * 新增
	 */
	public Integer add(AdminUser bean) throws BusinessException{
		try {
			return this.adminUserMapper.insert(bean);
		} catch (Exception e) {
			throw new BusinessException("信息已经存在");
		}
	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<AdminUser> listBean){
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.adminUserMapper.insertBatch(listBean);
	}

	/**
	 * 根据Id修改
	 */
	public Integer updateById(AdminUser bean,Integer id){
		return this.adminUserMapper.updateById(bean,id);
	}


	/**
	 * 根据Id删除
	 */
	public Integer deleteById(Integer id){
		return this.adminUserMapper.deleteById(id);
	}


	/**
	 * 根据Id获取对象
	 */
	public AdminUser getAdminUserById(Integer id){
		return this.adminUserMapper.selectById(id);
	}


	/**
	 * 根据Account修改
	 */
	public Integer updateByAccount(AdminUser bean,String account){
		return this.adminUserMapper.updateByAccount(bean,account);
	}


	/**
	 * 根据Account删除
	 */
	public Integer deleteByAccount(String account){
		return this.adminUserMapper.deleteByAccount(account);
	}


	/**
	 * 根据Account获取对象
	 */
	public AdminUser getAdminUserByAccount(String account){
		return this.adminUserMapper.selectByAccount(account);
	}

}